package spring.boot.mybatis.plus.service;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import spring.boot.mybatis.plus.mapper.TUserMapper;
import spring.boot.mybatis.plus.model.TUser;

@Slf4j
@Service
@DS("master")
@Transactional(rollbackFor = Exception.class)
public class TUserService extends ServiceImpl<TUserMapper, TUser> {

    public boolean updateUser(TUser tUser) {
        UpdateWrapper<TUser> wrapper = new UpdateWrapper<>();
        wrapper.set("username", tUser.getUsername());
        wrapper.set("age", tUser.getAge());
        wrapper.eq("id", tUser.getId());
        return update(wrapper);
    }

    public IPage<TUser> selectUserPage() {
        int pageNum = 1;
        int pageSize = 1;
        Page<TUser> page = new Page<>(pageNum, pageSize);
        return baseMapper.selectUserPage(page);
    }

    public IPage<TUser> selectUserPage2() {
        int pageNum = 1;
        int pageSize = 1;
        Page<TUser> page = new Page<>(pageNum, pageSize);
        return page(page);
    }


//    public Pages<TUser> selectUserPage2() {
//        QueryWrapper<TUser> wrapper = new QueryWrapper<>();
//        wrapper.eq("username", "Jack");
//        Pages<TUser> page = new Pages<>(10, 1);
//        Pages<TUser> pages = page(page, wrapper);
//        return pages;
//    }
}
